package cn.dulian.fruit.servlets;

import cn.dulian.fruit.dao.FruitDAO;
import cn.dulian.fruit.dao.impl.FruitDAOImpl;
import cn.dulian.fruit.pojo.Fruit;
import cn.dulian.myssm.myspringmvc.ViewBaseServlet;
import cn.dulian.myssm.myspringmvc.util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author dulian
 * @create 2022-04-07 20:09
 */
@WebServlet("/del.do")
public class DelServlet extends ViewBaseServlet {
    private FruitDAO fruitDAO = new FruitDAOImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String fidStr = req.getParameter("fid");
        if(StringUtil.isNotEmpty(fidStr)){
            int fid = Integer.parseInt(fidStr);
            fruitDAO.delFruitByFid(fid);
            //这里要重定向，因为要传两次，客户端发给服务端A， 服务端A 发回消息给客户端， 让它找服务端B
            resp.sendRedirect("index");
        }
    }
}
